package com.nifostasky.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nifostasky.dao.TUserDao;
import com.nifostasky.entity.TUser;
import com.nifostasky.service.TUserService;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * (TUser)表服务实现类
 *
 * @author makejava
 * @since 2021-09-28 16:44:19
 */
@Primary
@Service
public class TUserServiceImpl extends ServiceImpl<TUserDao, TUser> implements TUserService {

    @Override
    public void insertUserInfo(TUser tUser) {
        tUser.setGenTime(new Date());
        baseMapper.insert(tUser);
    }


    @Override
    public void updateUserInfo(TUser tUser) {
        tUser.setGenTime(new Date());
        baseMapper.updateById(tUser);
        Integer i= 1/0;
    }
    @Transactional(
            rollbackFor = Exception.class,
//            noRollbackFor = Exception.class,
            isolation = Isolation.SERIALIZABLE,
            propagation = Propagation.REQUIRED)
    public List<TUser> a(TUser tUser){
        return  testTransactional(tUser);
    }

    /**
     * 测试事务
     * @param tUser
     * @return
     */
    @Transactional(
            rollbackFor = Exception.class,
//            noRollbackFor = Exception.class,
            isolation = Isolation.SERIALIZABLE,
            propagation = Propagation.REQUIRED)
    public List<TUser> testTransactional(TUser tUser){
        insertUserInfo(tUser);
        tUser.setId(1L);
        tUser.setUsername("艹艹艹");
        updateUserInfo(tUser);
        return baseMapper.selectList(new QueryWrapper<TUser>());
    }

}
